package com.zhuss.core.processor;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.core.wrongWord.DeleteWrongWordBo;
import com.zhuss.bean.vo.core.wrongWord.DetailWrongWordVo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.core.db.dao.ext.WrongWordDao;
import com.zhuss.core.db.entity.WrongWord;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.WpsException;
import com.zhuss.util.JsonUtil;

/**
 * @description: 敏感字删除
 * @author: zhushanshuo
 * @create: Fri Nov 20 13:10:22 CST 2020
 **/
@Component("wrongWordDelete")
public class WrongWordDelete extends AbstractProcessor<Object, DeleteWrongWordBo> implements Processor<Object, DeleteWrongWordBo> {

    @Autowired
    private WrongWordDao wrongWordDao;
    
    @Autowired
	@Qualifier("wrongWordRead")
	private WrongWordRead wrongWordRead;
    
    
    /**
     * 校验
     */
	@Override
    public void check(DeleteWrongWordBo bo) throws WpsException {
		// TODO 删除 敏感字 校验， 请补充
    }
    
    /**
     * 操作方法
     */
    @Override
    public Object process(DeleteWrongWordBo param) throws WpsException {
    	Long wrongWordId = param.getWrongWordId();
    	String name = ((DetailWrongWordVo) wrongWordRead.detail(wrongWordId)).getName();
    	
    	WrongWord record = new WrongWord();
    	record.setWrongWordId(wrongWordId);
    	record.setDeleted(param.getDeleted());
    	
    	record.setModifierId(param.getConcurrentUserId());
    	record.setModifier(param.getConcurrentUserName());
    	record.setModifyTime(new Date());
    	wrongWordDao.delete(record);
    	param.setName(name);
        return null;
    }
    
    /**
     * 操作日志
     */
	@Override
	public Object log(DeleteWrongWordBo param) throws WpsException {
		OpLog record = new OpLog();
    	record.setMoudle(MoudleEnum.基础模块.key());
    	record.setAction(LogActionEnum.敏感字删除.key());
    	record.setTargetId(param.getWrongWordId());
    	record.setTargetName(param.getName());
    	record.setContent("参数: " + JsonUtil.toJson(param));
    	record.setReason(param.getExceptionReason());
    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
    	return null;
	}
}
